<template>
  <a-spin :spinning="confirmLoading">
    <!-- <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" slot="detail" :rules="validatorRules">
        <a-row>
          <a-col :span="7">
            <a-form-model-item label="变动类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag placeholder="选择商家类型" dictCode="merchant_type" v-model="model.businessType" />
            </a-form-model-item>
          </a-col>

          <a-col :span="7">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date
                placeholder="请选择开始时间"
                v-model="model.beginDate"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="1">
            <div style="line-height: 38px">至</div>
          </a-col>
          <a-col :span="7">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date
                placeholder="请选择结束时间"
                v-model="model.endDate"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="2">
            <div><a-button @click="submitForm" type="primary">查询</a-button></div>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container> -->

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate'
import JDictSelectTag from '@/components/dict/JDictSelectTag'

export default {
  mixins: [JeecgListMixin, mixinDevice],
  name: 'IncomeCotForm',
  components: {
    JFormContainer,
    JDate,
    JDictSelectTag,
  },
  props: {
    formData: {
      type: Object,
      default: () => {},
      required: false,
    },
    normal: {
      type: Boolean,
      default: false,
      required: false,
    },
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {},
      id: '',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        businessType: [{ required: true, message: '请选择商家类型！' }],
      },
      // 表头
      columns: [
      {
          title: '来源用户',
          align: 'center',
          dataIndex: 'sourceRealname',
        },
        // {
        //   title: '来源用户',
        //   align: 'center',
        //   dataIndex: 'sourceUserId',
        // },
        {
          title: '分佣等级',
          align: 'center',
          dataIndex: 'level',
        },
        // {
        //   title: '状态',
        //   align: 'center',
        //   dataIndex: 'status_dictText',
        // },
        {
          title: '收益',
          align: 'center',
          dataIndex: 'income',
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   fixed: 'right',
        //   width: 147,
        //   scopedSlots: { customRender: 'action' },
        // },
      ],
      url: {
        list: '/incomedetail/api/list',
        delete: '/sys/tenant/delete',
        deleteBatch: '/sys/tenant/deleteBatch',
        add: '/sys/tenant/add',
        edit: '/sys/tenant/edit',
        queryById: '/sys/tenant/queryById',
      },
    }
  },
  computed: {
    formDisabled() {
      if (this.normal === false) {
        if (this.formData.disabled === false) {
          return false
        } else {
          return true
        }
      }
      return this.disabled
    },
    disabledId() {
      return this.id ? true : false
    },
    showFlowSubmitButton() {
      if (this.normal === false) {
        if (this.formData.disabled === false) {
          return true
        } else {
          return false
        }
      } else {
        return false
      }
    },
  },
  created() {
    this.showFlowData()
  },
  methods: {
    show(record) {
      // this.model = record?Object.assign({}, record):this.model;
      // this.id = record?record.id:'';
      this.visible = true
    },
    showFlowData() {
      if (this.normal === false) {
        let params = { id: this.formData.dataId }
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result)
          }
        })
      }
    },
    submitForm() {
      const that = this
      console.log('model', this.model)
      return
      // 触发表单验证
      that.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                if ('该编号已存在!' == res.message) {
                  this.model.id = ''
                }
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        } else {
          return false
        }
      })
    },
    popupCallback(row) {
      this.model = Object.assign(this.model, row)
    },
  },
}
</script>
